<template>
  <view class="statistics-container">
    <!-- 页面标题 -->
    <view class="page-header">
      <view class="page-title slide-in-left">数据统计</view>
      <view class="page-subtitle slide-in-left" style="animation-delay: 0.1s;">及时了解商机进展</view>
    </view>

    <!-- 统计概览 -->
    <view class="stat-overview-card animate-card fade-in">
      <view class="card-title">
        <text>商机概览</text>
      </view>
      <view class="stat-grid">
        <view class="stat-item">
          <view class="stat-value">{{ stats.totalGroups }}</view>
          <view class="stat-label">负责集团</view>
          <view class="stat-progress">
            <view class="progress-inner" style="width: 80%;"></view>
          </view>
        </view>
        <view class="stat-item">
          <view class="stat-value">{{ stats.totalOpportunities }}</view>
          <view class="stat-label">总商机数</view>
          <view class="stat-progress">
            <view class="progress-inner" style="width: 65%; background-color: #19be6b;"></view>
          </view>
        </view>
        <view class="stat-item">
          <view class="stat-value">{{ stats.followingOpportunities }}</view>
          <view class="stat-label">跟进中</view>
          <view class="stat-progress">
            <view class="progress-inner" style="width: 50%; background-color: #ff9900;"></view>
          </view>
        </view>
        <view class="stat-item">
          <view class="stat-value">{{ stats.completedOpportunities }}</view>
          <view class="stat-label">已落地</view>
          <view class="stat-progress">
            <view class="progress-inner" style="width: 40%; background-color: #9c26b0;"></view>
          </view>
        </view>
      </view>
    </view>

    <!-- 产品类型分布 -->
    <view class="stat-chart-card animate-card fade-in" style="animation-delay: 0.1s;">
      <view class="card-title">
        <text>产品类型分布</text>
        <view class="card-subtitle">共 {{getTotalProducts()}} 个商机项目</view>
      </view>
      <view class="chart-container" id="productTypeChart">
        <view class="pie-chart" v-if="chartRendered">
          <view
            class="pie-segment"
            v-for="(item, index) in productTypes"
            :key="index"
            :style="{
              background: item.color,
              transform: `rotate(${getRotation(index)}deg)`,
              '--rotation': getRotation(index),
              clip: `rect(0px, 120px, 240px, 0px)`,
              opacity: selectedType === null || selectedType === index ? 1 : 0.4
            }"
            @click="selectProductType(index)"
          ></view>
          <view class="pie-center">
            <text v-if="selectedType !== null">{{productTypes[selectedType].count}}</text>
            <text v-else>{{getTotalProducts()}}</text>
          </view>
        </view>
        <u-empty v-else mode="data" text="正在加载数据..."></u-empty>
      </view>
      <view class="stat-legend">
        <view
          class="legend-item"
          v-for="(item, index) in productTypes"
          :key="index"
          @click="selectProductType(index)"
          :class="{'selected': selectedType === index}"
        >
          <view class="legend-color" :style="{ backgroundColor: item.color }"></view>
          <view class="legend-text">{{ item.name }}</view>
          <view class="legend-value">{{ item.count }}</view>
        </view>
      </view>
    </view>

    <!-- 商机状态统计 -->
    <view class="stat-chart-card animate-card fade-in" style="animation-delay: 0.2s;">
      <view class="card-title">
        <u-icon name="calendar" size="20" color="#007aff"></u-icon>
        <text>信息化拓展进度</text>
        <view class="card-actions">
          <u-icon name="refresh" size="18" color="#999" @click="refreshData"></u-icon>
        </view>
      </view>
      <view class="progress-list">
        <view class="progress-item" v-for="(item, index) in progressData" :key="index">
          <view class="progress-info">
            <view class="progress-name">{{ item.name }}</view>
            <view class="progress-value">{{ item.completed }}/{{ item.total }}</view>
          </view>
          <view class="progress-bar">
            <view
              class="progress-bar-inner animate-progress"
              :style="{ 
                '--final-width': item.percentage + '%', 
                backgroundColor: item.color,
                animationDelay: index * 0.1 + 's'
              }"
            >
              <text v-if="item.percentage > 15">{{item.percentage}}%</text>
            </view>
            <text v-if="item.percentage <= 15" class="progress-text-outside">{{item.percentage}}%</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 趋势分析 -->
    <view class="stat-chart-card animate-card fade-in" style="animation-delay: 0.3s;">
      <view class="card-title">
        <text>集团单位商机排名</text>
        <view class="card-tabs">
          <view
            class="tab-item"
            :class="{'active': trendType === 'count'}"
            @click="switchTrendType('count')"
          >数量</view>
          <view
            class="tab-item"
            :class="{'active': trendType === 'amount'}"
            @click="switchTrendType('amount')"
          >金额</view>
        </view>
      </view>
      <view class="chart-container" id="rankingChart">
        <scroll-view scroll-y class="ranking-list" v-if="chartRendered">
          <view
            class="ranking-item scale-in-hover"
            v-for="(item, index) in currentRankingData"
            :key="index"
            :class="{'top-three': index < 3}"
            @click="navigateToGroup(item.groupCode)"
          >
            <view class="ranking-index">{{ index + 1 }}</view>
            <view class="ranking-info">
              <view class="ranking-name">{{ item.name }}</view>
              <view class="ranking-progress">
                <view
                  class="ranking-progress-inner animate-width"
                  :style="{
                    '--final-width': (item.value / getMaxRankingValue() * 100) + '%',
                    backgroundColor: index < 3 ? rankingColors[index] : '#909399',
                    animationDelay: index * 0.05 + 's'
                  }"
                ></view>
              </view>
            </view>
            <view class="ranking-value">{{ item.value }}{{ trendType === 'amount' ? '万' : '' }}</view>
          </view>
        </scroll-view>
        <u-empty v-else mode="data" text="正在加载数据..."></u-empty>
      </view>
    </view>

    <!-- 低质态集团单位统计 -->
    <view class="stat-list-card animate-card fade-in" style="animation-delay: 0.4s;">
      <view class="card-title">
        <u-icon name="warning" size="20" color="#f56c6c"></u-icon>
        <text>低质态集团单位</text>
        <view class="card-subtitle">本网份额低于(小于等于)45% · {{ lowQualityGroups.length }}个</view>
      </view>
      <view class="low-quality-list" v-if="lowQualityGroups.length > 0">
        <view
          class="low-quality-item scale-in-hover"
          v-for="(item, index) in lowQualityGroups"
          :key="index"
          @click="navigateToGroup(item.groupCode)"
        >
          <view class="low-quality-main">
            <view class="low-quality-icon" :class="getIndustryClass(item.industry || '其他')">
              <text>{{ getFirstChar(item.name) }}</text>
            </view>
            <view class="low-quality-info">
              <view class="low-quality-name">{{ item.name }}</view>
              <view class="low-quality-percentage">
                <view class="percentage-bar">
                  <view
                    class="percentage-bar-inner animate-width"
                    :style="{ 
                      '--final-width': item.networkShare + '%',
                      animationDelay: index * 0.1 + 's' 
                    }"
                    :class="{'critical': item.networkShare <= 40}"
                  ></view>
                </view>
                <text class="percentage-text">{{ item.networkShare }}%</text>
              </view>
            </view>
          </view>
          <u-icon name="arrow-right" size="18" color="#c0c4cc"></u-icon>
        </view>
      </view>
      <view class="empty-list" v-else>
        <u-empty mode="car" text="暂无低质态集团单位"></u-empty>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      chartRendered: false,
      selectedType: null,
      trendType: "count",
      stats: {
        totalGroups: 0,
        totalOpportunities: 0,
        followingOpportunities: 0,
        completedOpportunities: 0
      },
      productTypes: [],
      progressData: [],
      countTrendData: [
        { groupCode: "GOV001", name: "平凉市政府", value: 12 },
        { groupCode: "EDU001", name: "平凉市教育局", value: 10 },
        { groupCode: "MED001", name: "平凉市人民医院", value: 8 },
        { groupCode: "SCH001", name: "平凉市第一中学", value: 7 },
        { groupCode: "SCH002", name: "平凉市第二中学", value: 6 },
        { groupCode: "POL001", name: "平凉市公安局", value: 5 },
        { groupCode: "FIN001", name: "平凉市财政局", value: 4 },
        { groupCode: "TAX001", name: "平凉市税务局", value: 3 }
      ],
      amountTrendData: [
        { groupCode: "GOV001", name: "平凉市政府", value: 28.5 },
        { groupCode: "EDU001", name: "平凉市教育局", value: 22.8 },
        { groupCode: "MED001", name: "平凉市人民医院", value: 18.4 },
        { groupCode: "POL001", name: "平凉市公安局", value: 15.6 },
        { groupCode: "SCH001", name: "平凉市第一中学", value: 12.2 },
        { groupCode: "FIN001", name: "平凉市财政局", value: 10.5 },
        { groupCode: "SCH002", name: "平凉市第二中学", value: 8.9 },
        { groupCode: "TAX001", name: "平凉市税务局", value: 6.7 }
      ],
      lowQualityGroups: [],
      rankingColors: ["#ff9900", "#19be6b", "#007aff"]
    };
  },
  computed: {
    currentRankingData() {
      return this.trendType === "count"
        ? this.countTrendData
        : this.amountTrendData;
    }
  },
  onLoad() {
    // 获取数据
    this.getStatisticsData();
  },
  onShow() {
    // 页面显示时刷新数据
    console.log("统计页面显示");
    this.getStatisticsData();
  },
  mounted() {
    // 在真实项目中，这里可以初始化图表
    setTimeout(() => {
      this.chartRendered = true;
    }, 800);
  },
  methods: {
    // 获取统计数据
    getStatisticsData() {
      uni.showLoading({
        title: "加载中..."
      });

      // 获取商机概览数据
      this.getStatisticsOverview();

      // 获取产品类型分布
      this.getProductDistribution();

      // 获取拓展进度数据
      this.getExpansionProgress();

      // 获取低质态集团单位
      this.getLowQualityGroups();

      // 获取集团单位商机排名数据
      this.getGroupRanking("count");
      this.getGroupRanking("amount");
    },

    // 获取商机概览
    getStatisticsOverview() {
      this.$http
        .sendRequest("zhanke/statistics_overview", "POST", {})
        .then(res => {
          if (res.data && res.data.code === 200) {
            this.stats = res.data.data;
            console.log("获取商机概览成功:", this.stats);
          } else {
            console.error("获取商机概览失败:", res.data.msg);
          }
        })
        .catch(err => {
          console.error("获取商机概览异常:", err);
        });
    },

    // 获取产品类型分布
    getProductDistribution() {
      this.$http
        .sendRequest("zhanke/product_distribution", "POST", {})
        .then(res => {
          if (res.data && res.data.code === 200) {
            this.productTypes = res.data.data;
            console.log("获取产品类型分布成功:", this.productTypes);
          } else {
            console.error("获取产品类型分布失败:", res.data.msg);
          }
        })
        .catch(err => {
          console.error("获取产品类型分布异常:", err);
        });
    },

    // 获取拓展进度数据
    getExpansionProgress() {
      this.$http
        .sendRequest("zhanke/expansion_progress", "POST", {})
        .then(res => {
          if (res.data && res.data.code === 200) {
            this.progressData = res.data.data;
            console.log("获取拓展进度成功:", this.progressData);
          } else {
            console.error("获取拓展进度失败:", res.data.msg);
          }
        })
        .catch(err => {
          console.error("获取拓展进度异常:", err);
        })
        .finally(() => {
          // 所有数据加载完成后，隐藏加载中提示
          uni.hideLoading();
        });
    },

    // 获取低质态集团单位
    getLowQualityGroups() {
      this.$http
        .sendRequest("zhanke/low_quality_groups", "POST", {})
        .then(res => {
          if (res.data && res.data.code === 200) {
            // 直接使用后台传递的行业字段，如果没有则使用默认分配
            this.lowQualityGroups = res.data.data.map((item, index) => {
              // 确保有groupCode字段
              let groupCode = item.groupCode || item.id;
              // 使用后台传递的行业，如果没有则按索引分配
              let industry = item.industry;

              // 如果后台没有提供行业，按索引轮换分配
              if (!industry) {
                const industries = [
                  "创新",
                  "党政",
                  "融合",
                  "公检法",
                  "金融",
                  "交通",
                  "工业能源",
                  "农商",
                  "科教",
                  "医卫"
                ];
                industry = industries[index % industries.length];
              }

              return {
                ...item,
                groupCode: groupCode,
                industry: industry
              };
            });
            console.log("获取低质态集团单位成功:", this.lowQualityGroups);
          } else {
            console.error("获取低质态集团单位失败:", res.data.msg);
          }
        })
        .catch(err => {
          console.error("获取低质态集团单位异常:", err);
        });
    },

    // 获取集团单位商机排名
    getGroupRanking(type) {
      this.$http
        .sendRequest("zhanke/group_ranking", "POST", {
          type: type,
          limit: 10
        })
        .then(res => {
          if (res.data && res.data.code === 200) {
            if (type === "count") {
              this.countTrendData = res.data.data;
            } else {
              this.amountTrendData = res.data.data;
            }
            console.log(`获取${type}排名成功:`, res.data.data);
          } else {
            console.error(`获取${type}排名失败:`, res.data.msg);
          }
        })
        .catch(err => {
          console.error(`获取${type}排名异常:`, err);
        });
    },

    // 刷新数据
    refreshData() {
      this.chartRendered = false;
      this.getStatisticsData();
      setTimeout(() => {
        this.chartRendered = true;
      }, 800);

      uni.showToast({
        title: "数据已更新",
        icon: "success"
      });
    },

    // 选择产品类型
    selectProductType(index) {
      if (this.selectedType === index) {
        this.selectedType = null;
      } else {
        this.selectedType = index;
      }
    },

    // 切换趋势类型
    switchTrendType(type) {
      this.trendType = type;
    },

    // 获取产品总数
    getTotalProducts() {
      if (!this.productTypes || this.productTypes.length === 0) {
        return 0;
      }
      return this.productTypes.reduce((sum, item) => sum + item.count, 0);
    },

    // 获取饼图旋转角度
    getRotation(index) {
      let totalCount = this.getTotalProducts();
      if (totalCount === 0) return 0;

      let startAngle = 0;
      for (let i = 0; i < index; i++) {
        startAngle += (this.productTypes[i].count / totalCount) * 360;
      }
      return startAngle;
    },

    // 获取趋势最大值
    getMaxRankingValue() {
      if (!this.currentRankingData || this.currentRankingData.length === 0) {
        return 1;
      }
      return Math.max(...this.currentRankingData.map(item => item.value)) * 1.2;
    },

    // 跳转到集团详情
    navigateToGroup(groupCode) {
      if (!groupCode) {
        uni.showToast({
          title: "缺少集团编码",
          icon: "none"
        });
        return;
      }

      uni.navigateTo({
        url: `/pages/group/detail?groupCode=${groupCode}`
      });
    },

    // 获取字符串的首字符
    getFirstChar(str) {
      if (!str || typeof str !== "string" || str.length === 0) {
        return "?";
      }
      try {
        return str.charAt(0);
      } catch (e) {
        console.error("获取首字符失败:", e);
        return "?";
      }
    },

    // 获取行业对应的样式类
    getIndustryClass(industry) {
      const industryMap = {
        创新: "avatar-innovation",
        党政: "avatar-government",
        融合: "avatar-fusion",
        公检法: "avatar-legal",
        金融: "avatar-finance",
        交通: "avatar-transport",
        工业能源: "avatar-industry",
        农商: "avatar-agriculture",
        科教: "avatar-education",
        医卫: "avatar-medical"
      };
      return industryMap[industry] || "avatar-default";
    }
  }
};
</script>

<style>
.statistics-container {
  min-height: 100vh;
  background-color: #f5f7fa;
  padding-bottom: 30px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

.page-header {
  background: linear-gradient(120deg, #007aff, #0056b3);
  padding: 60px 20px 25px;
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.page-subtitle {
  font-size: 15px;
  opacity: 0.8;
  margin-top: 8px;
}

.animate-card {
  animation: slideUp 0.5s ease-out;
  transition: all 0.3s ease;
  animation-fill-mode: both;
  will-change: transform, opacity;
}

@keyframes slideUp {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.stat-overview-card,
.stat-chart-card,
.stat-list-card {
  margin: 15px;
  padding: 18px;
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 3px 15px 0 rgba(0, 0, 0, 0.05);
}

.stat-overview-card:active,
.stat-chart-card:active,
.stat-list-card:active {
  transform: scale(0.98);
}

.card-title {
  font-size: 16px;
  color: #222222;
  font-weight: bold;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  position: relative;
}

.card-title text {
  margin-left: 6px;
}

.card-subtitle {
  font-size: 12px;
  color: #909399;
  font-weight: normal;
  margin-left: auto;
}

.card-actions {
  margin-left: auto;
}

.card-tabs {
  margin-left: auto;
  display: flex;
  background-color: #f5f7fa;
  border-radius: 20px;
  overflow: hidden;
}

.tab-item {
  padding: 4px 12px;
  font-size: 12px;
  color: #606266;
  transition: all 0.3s;
  letter-spacing: 0.2px;
}

.tab-item.active {
  background-color: #007aff;
  color: #ffffff;
  font-weight: 600;
  text-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.2);
}

.stat-grid {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

.stat-item {
  width: 25%;
  text-align: center;
  padding: 10px 5px;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: #007aff;
  margin-bottom: 5px;
  text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.stat-label {
  font-size: 12px;
  color: #606266;
  margin-bottom: 8px;
}

.stat-progress {
  height: 3px;
  background-color: #ebeef5;
  border-radius: 3px;
  overflow: hidden;
  margin: 0 auto;
  width: 80%;
}

.progress-inner {
  height: 100%;
  background-color: #007aff;
  border-radius: 3px;
}

.chart-container {
  height: 240px;
  margin: 15px 0;
  position: relative;
}

.pie-chart {
  width: 240px;
  height: 240px;
  position: relative;
  margin: 0 auto;
  border-radius: 50%;
  overflow: hidden;
}

.pie-segment {
  position: absolute;
  width: 50%;
  height: 100%;
  transform-origin: 100% 50%;
  left: 0;
  top: 0;
  transition: all 0.3s ease;
}

.pie-center {
  position: absolute;
  width: 100px;
  height: 100px;
  background-color: #fff;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  font-size: 24px;
  font-weight: bold;
  color: #222222;
  text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.stat-legend {
  display: flex;
  flex-wrap: wrap;
  margin-top: 20px;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  margin-right: 15px;
  margin-bottom: 10px;
  background: #f8f9fa;
  padding: 5px 10px;
  border-radius: 20px;
  transition: all 0.3s;
  cursor: pointer;
}

.legend-item:active,
.legend-item.selected {
  background: #e8f4ff;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 6px;
}

.legend-text {
  font-size: 12px;
  color: #606266;
  margin-right: 6px;
  letter-spacing: 0.2px;
}

.legend-value {
  font-size: 12px;
  color: #222222;
  font-weight: bold;
  text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.progress-list {
  margin-top: 15px;
}

.progress-item {
  margin-bottom: 18px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.progress-name {
  font-size: 14px;
  color: #222222;
  font-weight: 500;
  letter-spacing: 0.3px;
}

.progress-value {
  font-size: 14px;
  color: #007aff;
  font-weight: 600;
  text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.progress-bar {
  height: 20px;
  background-color: #f2f3f5;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.progress-bar-inner {
  height: 100%;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
  color: #fff;
  font-size: 12px;
  transition: width 0.5s ease;
}

.progress-text-outside {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: #606266;
}

.ranking-list {
  height: 100%;
  position: relative;
}

.ranking-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 10px;
  border-bottom: 1px solid #f0f0f0;
  position: relative;
  background-color: #ffffff;
  transition: background-color 0.3s ease;
}

.ranking-item:last-child {
  border-bottom: none;
}

.ranking-item:hover {
  background-color: #f9fafc;
}

.ranking-index {
  font-size: 16px;
  color: #333333;
  font-weight: bold;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background-color: #f5f7fa;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.top-three .ranking-index {
  color: #ffffff;
  text-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.2);
}

.top-three:nth-child(1) .ranking-index {
  background-color: #ff9900;
}

.top-three:nth-child(2) .ranking-index {
  background-color: #19be6b;
}

.top-three:nth-child(3) .ranking-index {
  background-color: #007aff;
}

.ranking-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.ranking-name {
  font-size: 15px;
  color: #222222;
  margin-bottom: 6px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.ranking-progress {
  width: 100%;
  height: 8px;
  background-color: #f2f3f5;
  border-radius: 4px;
  overflow: hidden;
}

.ranking-progress-inner {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.ranking-value {
  font-size: 16px;
  color: #007aff;
  font-weight: bold;
  margin-left: 15px;
  text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.top-three {
  background-color: #f9fafc;
}

.empty-list {
  padding: 20px 0;
}

.low-quality-list {
  margin-top: 15px;
}

.low-quality-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 10px;
  border-bottom: 1px solid #f0f0f0;
  position: relative;
}

.low-quality-item:last-child {
  border-bottom: none;
}

.low-quality-item:active {
  background-color: #f5f7fa;
}

.low-quality-main {
  display: flex;
  align-items: center;
}

.low-quality-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
  font-size: 18px;
  font-weight: bold;
  color: #ffffff;
  text-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.2);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
}

.low-quality-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.low-quality-name {
  font-size: 15px;
  color: #222222;
  margin-bottom: 6px;
  font-weight: 500;
  letter-spacing: 0.3px;
  text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.low-quality-percentage {
  display: flex;
  align-items: center;
}

.percentage-bar {
  width: 100px;
  height: 10px;
  background-color: #f2f3f5;
  border-radius: 5px;
  overflow: hidden;
  margin-right: 10px;
}

.percentage-bar-inner {
  height: 100%;
  border-radius: 5px;
  background-color: #f56c6c;
  transition: width 0.5s ease;
}

.percentage-text {
  font-size: 12px;
  color: #606266;
  font-weight: bold;
  text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.critical {
  background-color: #ff9900;
}

.slide-in-left {
  animation: slideInLeft 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

@keyframes slideInLeft {
  0% {
    transform: translateX(-20px);
    opacity: 0;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

.fade-in {
  animation: fadeIn 0.8s ease-out both;
}

@keyframes fadeIn {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-progress {
  animation: progressGrow 1s ease-out forwards;
  transform-origin: left;
  width: 0 !important; /* Initial state */
}

@keyframes progressGrow {
  0% {
    width: 0%;
  }
  100% {
    width: calc(var(--final-width, 100%));
  }
}

.animate-width {
  animation: widthGrow 1s ease-out forwards;
  width: 0 !important; /* Initial state */
}

@keyframes widthGrow {
  0% {
    width: 0%;
  }
  100% {
    width: calc(var(--final-width, 100%));
  }
}

.pie-segment:hover {
  transform-origin: 100% 50%;
  transform: scale(1.02) rotate(calc(var(--rotation, 0) * 1deg));
}

.scale-in-hover {
  transition: all 0.25s ease-out;
}

.scale-in-hover:active {
  transform: scale(0.98);
  background-color: rgba(0, 122, 255, 0.05);
}

.legend-item {
  transition: all 0.3s ease;
}

.legend-item:hover {
  transform: translateX(5px);
  background: rgba(0, 122, 255, 0.1);
}

/* 增强卡片悬浮效果 */
.stat-overview-card,
.stat-chart-card,
.stat-list-card {
  transition: all 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-overview-card:hover,
.stat-chart-card:hover,
.stat-list-card:hover {
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

/* 提升刷新按钮的交互体验 */
.card-actions {
  transition: all 0.3s ease;
}

.card-actions:hover {
  transform: rotate(30deg);
}

/* 提升标签切换的动画 */
.tab-item {
  position: relative;
  overflow: hidden;
}

.tab-item.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #007aff;
  z-index: -1;
  animation: slideIn 0.3s ease-out forwards;
}

@keyframes slideIn {
  0% {
    transform: translateY(100%);
  }
  100% {
    transform: translateY(0);
  }
}

.card-title {
  position: relative;
}

.card-title::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 0;
  width: 40px;
  height: 3px;
  background: linear-gradient(to right, #007aff, transparent);
  border-radius: 3px;
}

.animate-card {
  animation-fill-mode: both;
  will-change: transform, opacity;
}

.timeline-date {
  font-size: 14px;
  font-weight: bold;
  color: #606266;
  text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.timeline-body {
  font-size: 14px;
  color: #222222;
  line-height: 1.5;
  letter-spacing: 0.2px;
}

.product-name {
  font-size: 14px;
  color: #222222;
  margin-bottom: 4px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.product-count {
  font-size: 18px;
  font-weight: bold;
  color: #222222;
  text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.stat-chart-card .card-subtitle,
.stat-list-card .card-subtitle {
  font-size: 12px;
  color: #606266;
  font-weight: 400;
  margin-left: auto;
  letter-spacing: 0.2px;
}

.avatar-government {
  background: linear-gradient(135deg, #0abd5a, #07964d);
}
.avatar-education {
  background: linear-gradient(135deg, #ff9500, #f57c00);
}
.avatar-medical {
  background: linear-gradient(135deg, #f55c5c, #e53935);
}
.avatar-finance {
  background: linear-gradient(135deg, #9c27b0, #7b1fa2);
}
.avatar-transport {
  background: linear-gradient(135deg, #3498db, #2980b9);
}
.avatar-industry {
  background: linear-gradient(135deg, #e67e22, #d35400);
}
.avatar-agriculture {
  background: linear-gradient(135deg, #2ecc71, #27ae60);
}
.avatar-innovation {
  background: linear-gradient(135deg, #1abc9c, #16a085);
}
.avatar-fusion {
  background: linear-gradient(135deg, #34495e, #2c3e50);
}
.avatar-legal {
  background: linear-gradient(135deg, #8e44ad, #6c3483);
}
.avatar-default {
  background: linear-gradient(135deg, #f56c6c, #ff9900);
}
</style> 